# 题目一:以Lena为原始图像，通过OpenCV实现平均滤波，高斯滤波及中值滤波，比较滤波结果
import cv2 as cv

filename = r"D:\AI\Picture\lena.jpg"
img = cv.imread(filename)
# 平均滤波
imgAverage = cv.blur(img, (5, 5))
# 高斯滤波
imgGauss = cv.GaussianBlur(img, (5, 5), 0)
# 中值滤波
imgMedian = cv.medianBlur(img, 5)
# 形态学滤波
kernel = cv.getStructuringElement(cv.MORPH_RECT, (3, 3))  # 定义矩形结构元素
imgOpen = cv.morphologyEx(img, cv.MORPH_OPEN, kernel, iterations=1)

cv.imshow("source image", img)
cv.imshow("imgAverage", imgGauss)
cv.imshow("imgGauss", imgGauss)
cv.imshow("imgMedian", imgGauss)
cv.imshow("imgOpen", imgGauss)

cv.waitKey()
cv.destroyAllWindows()
